﻿using System;
using System.Diagnostics;
using NLog;

namespace NewsMine.Logging
{
    public class NewsMineLogManager
    {
        //private NewsMineLogger logger;

        [ThreadStatic]
        public static string SessionId;
      
        /// <summary>
        /// Gets current class named Logger. 
        /// AVOID USING THIS AS IT MAY HAVE PERFORMANCE IMPACT.
        /// USE GetLogger(Name).
        /// </summary>
        /// <returns>Logger object</returns>
        [Obsolete("Use GetLogger(typeof(currentclass)) to avoid performance issues.")]
        public static INewsMineLogger GetCurrentLogger()
        {
            var stackTrace = new StackTrace();
            var type = stackTrace.GetFrame(1).GetMethod().DeclaringType;
            return GetLogger(type.FullName);
        }

        /// <summary>
        /// Gets named Logger instance
        /// </summary>
        /// <param name="name">The logger name</param>
        /// <param name="isTest">?</param>
        /// <returns>Logger object</returns>
        public static INewsMineLogger GetLogger(string name, bool isTest = false)
        {
            return new NewsMineLogger(LogManager.GetLogger(name));
        }

        /// <summary>
        /// Gets a named Logger instance for the specified type
        /// </summary>
        /// <param name="type">The type the logger is logging for.</param>
        /// <returns>Logger object</returns>
        public static INewsMineLogger GetLogger(Type type)
        {
            return GetLogger(type.FullName);
        }
    }
}
